import React, { useReducer } from "react";
import { Button } from "antd";

const initialState = { count:0 }
function reducer(state, { type }) {
  switch (type) {
    case 'add':
      return { count: state.count+1}
    case 'sub':
      return {count:state.count-1}
    default:
      break;
  }
}
export default function TestReducer() {
  const [state, dispatch] = useReducer(reducer, initialState)
  return (
    <div>
      <h2>useReducer</h2>
      <h5>count: {state.count}</h5>
      <Button onClick={()=>dispatch({type:'add'})}>count++</Button>
      <Button onClick={()=>dispatch({type:'sub'})}>count--</Button>
    </div>
  )
}


